package LeetCode热题HOT100;

import 剑指offer.ListNode;

public class p19删除链表的倒数第N个结点 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode pHead=new ListNode();
        pHead.next=head;

        ListNode cur=head;
        int size=0;
        while (cur!=null) {
            size++;
            cur=cur.next;
        }

        cur=pHead;
        for (int i = 0; i <size-n; i++) {
            cur=cur.next;
        }

        cur.next=cur.next.next;
        return pHead.next;
    }
}
